<template>
  <div class="addBut">
    <button @click="handelSub">-</button>
    <input :value="value">
    <button @click="handelAdd">+</button>
  </div>
</template>

<script>
// 数据父传子
// 修改子传父
export default {
  props: {
    value: {
      type: Number,
      default: 1
    }
  },
  methods: {
    handelAdd () {
      this.$emit('input', this.value + 1)
    },
    handelSub () {
      if (this.value <= 1) {
        return
      }
      this.$emit('input', this.value - 1)
    }
  }
}
</script>

<style scoped>
    .addBut{
        width: 100px;
    }
    button{
        width: 30px;
        outline: none;
        border: none;
        background-color: #efefef;
    }
    input{
        width: 30px;
        margin: 0 5px;
        outline: none;
        border: none;
        background-color: #efefef;
        text-align: center;
    }
</style>
